import {defineStore} from 'pinia'

interface IState{
    name:string,
    age:number,
    job:string
}
const useUserInfoStore=defineStore('userInfo',{
    state:():IState=>{
        return{
            name:'张三丰',
            age:120,
            job:'武当掌门'
        }
    },
    getters:{
        getUserInfo:(state:IState)=>`我叫${state.name},今年${state.age}岁,我的任职是${state.job}`
    },
    actions:{
        modifyUserInfo(name:string,age:number,job:string){
            this.name=name
            this.age=age
            this.job=job
        }
    },
    persist:{
        enabled:true,
        strategies:[
            {
                key:'giles-key',
                storage:localStorage,
                paths:['name','age']
            }
        ]
    }
})
export default useUserInfoStore